#if($subject.widget)
#set($vote=$subject.widget)
<script type="text/javascript">
var maxCheckedCount = ${vote.optionalQuantity}; 
function vote(id){
	var optionsOrder = new Array();
	$("input[name=option]").each(function(i,e){
		if($(e).attr("checked")){
			optionsOrder.push($(e).val());
		}
	});
	if(optionsOrder.length == 0){
		alert("请至少选择一项");
		return;
	}
	var data = {optionsOrder : optionsOrder};
	$.post(forum.baseURL + "/vote/" + id + "?_method=PUT", data, function(json){
		if(json.success){
			location.href = location.href;
		} else {
			alert("投票失败");
		}
	},"json");
}
function canSubmit(t){
	var checkedCount = 0;
	$("input[name=option]").each(function(i,e){
		if($(e).attr("checked")){
			++ checkedCount;
		}
	});
	if(checkedCount > maxCheckedCount){
		$(t).attr("checked", false);
		alert("最多只能选择" + maxCheckedCount + "项");
		-- checkedCount;
	}
	if(checkedCount == 0){
		$('#vote_result .submit').attr('disabled', 'disabled');
	} else{
		$('#vote_result .submit').removeAttr('disabled');
	}
}
function showVoteResult(){
	$('#vote_result table:last').hide();
	$('a.showResult').hide();
	$('button.submit').hide();
	$('#vote_result table:first').show();
	$('a.showVote').show();
}
function showVote(){
	$('#vote_result table:first').hide();
	$('a.showVote').hide();
	$('#vote_result table:last').show();
	$('a.showResult').show();
	$('button.submit').show();
}
</script>
<div id="vote_result">
	<div class="vote_info">
		#if($vote.optionalQuantity > 1)
		多选投票，最多可选 <b>${vote.optionalQuantity}</b> 项，目前共有 ${vote.voteAmount} 票
		#else
		单选投票，目前共有${vote.voteAmount}票
		#end
	</div>
	
	<table width="100%" cellspacing="0" cellpadding="0" #if(!$hasVoted)style="display:none;"#end>
		<tbody>
			#foreach($option in $vote.options)
				<tr>
					<td class="option">
					<label for="option_${foreach.count}"><span class="ordinal">${foreach.count}.</span>${option.content}</label>
					</td>
					<td> </td>
				</tr>
				
				<tr>
					<td class="optionvessel">
						<div class="optionbg">
							#set($width=$option.count/$vote.voteAmount)
							#set($color=$vote.options.size()+$foreach.index%10)
							#if($option.count==0)
								<div style="width:2px" class="polloptionbar pollcolor${color}">&nbsp;</div>							
							#else
								<div style="width:$utils.percent($width)" class="polloptionbar pollcolor${color}">&nbsp;</div>										
							#end
						</div>
					</td>
					<td>
						#if($vote.voteAmount==0)
						0%
						#else
						$utils.percent($width)						
						#end
						<em class="pollvote5">($option.count)</em>
					</td>
				</tr>
			#end
		</tbody>
	</table>
	#if($hasVoted)
	<center>您已经投过票了</center>
	#else 
	<table width="100%" cellspacing="0" cellpadding="0">
		<tbody>
			#foreach($option in $vote.options)
				<tr>
					<td class="selector">
					#if($vote.optionalQuantity>1)
						<input type="checkbox" onclick="canSubmit(this)" value="${foreach.index}" name="option" id="option_${foreach.count}" class="checkbox">
					#else
						<input type="radio" onclick="canSubmit(this)" value="${foreach.index}" name="option" id="option_${foreach.count}" class="checkbox">
					#end
					</td>
					<td class="option">
					<label for="option_${foreach.count}"><span class="ordinal">${foreach.count}.</span>${option.content}</label>
					</td>
					<td> </td>
				</tr>
				<tr>
					<td colspan="3" class="solidline">&nbsp;</td>
				</tr>
			#end
		</tbody>
	</table>
	<div>
		<button class="submit" disabled="disabled" onclick="vote($vote.id)">提交</button>
		<a class="showResult" style="font-size:12px;" href="javascript:showVoteResult();">查看结果</a>
		<a class="showVote" style="font-size:12px;display:none" href="javascript:showVote();">返回投票</a>
	</div>
	#end
</div>
#end